﻿/***************
 * Copyright 2009 (C) 
 * Timur Fanshteyn
 * Blog: http://blog.tfanshteyn.com
 * ************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Reflection;

namespace Coherence.Linq
{

    internal class SelectionProjection
    {
        internal Expression Selector;
    }

    internal class SelectionProjector : ExpressionVisitor
    {
        internal SelectionProjector()
        {
        }

        internal SelectionProjection ProjectColumns(Expression expression, ParameterExpression row)
        {
            Expression selector = this.Visit(expression);
            return new SelectionProjection { Selector = selector };
        }

        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter)
            {
                return Expression.PropertyOrField(null, m.Member.Name);
            }
            else
            {
                return base.VisitMemberAccess(m);
            }
        }
    }
}